package com.wisemoresystem.seal.action.seal.destroy;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_over_log;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.BankService;
import com.wisemoresystem.seal.service.SealDestroyService;
import com.wisemoresystem.seal.service.SealSetService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章销毁 接收
 * 
 * @author hxj
 *
 */
@Controller("ixSealDestroyRecieve")
@Scope("prototype")
@RequestMapping("/ix/seal/destroy/recieve")
public class SealDestroyRecieveAction extends ProjBaseAction {

	@Autowired
	private SealDestroyService service;
	@Autowired
	private BankService bService;
	@Autowired
	private SealSetService sealService;

	// t_seal flag_stop=上缴停用
	/**
	 * 印章销毁接收列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = service.selectSealDestroyRecieveList(
				WebTools.getCurrentBankId(), srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/destroy/recieve/list");
		mv.addObject("list", list);
		return mv;
	}

	// 转到接收页面
	/**
	 * 转到接收页面
	 * 
	 * @param seal_id
	 *            印章id
	 * @param verify_destory
	 *            检查销毁信息
	 * @return
	 */
	@RequestMapping("/recieve_form")
	public ModelAndView recieve_form(String seal_id, String verify_destory) {

		t_seal seal = service.findObjById(seal_id, t_seal.class);
		t_seal_over_log log = service.selectOverLogByIDs(seal_id,
				WebTools.getCurrentBankId());
		List<Map<String, Object>> userlist = sealService.selectSealUserList();

		ModelAndView mv = new ModelAndView(
				"/jsp/seal/destroy/recieve/recieve_form");
		mv.addObject("seal", seal);
		if (ChkTools.isNotNull(seal.getSeal_new_id())) {
			t_seal_new mac = service.findObjById(seal.getSeal_new_id(),
					t_seal_new.class);
			if (ChkTools.isNotNull(mac.getSeal_type_config_id())) {
				t_seal_type_config ma = service.findObjById(
						mac.getSeal_type_config_id(), t_seal_type_config.class);
				mv.addObject("ma", ma);
			}
			mv.addObject("mac", mac);
		}
		if (ChkTools.isNotNull(seal.getBank_id())) {
			t_bank bank = service.findObjById(log.getApply_bank_id(),
					t_bank.class);
			mv.addObject("bank", bank);
			t_bank superBank = service.findObjById(bank.getSuper_id(),
					t_bank.class);
			mv.addObject("superBank", superBank);
		}
		mv.addObject("userlist", userlist);
		return mv;

	}

	// 接收
	/**
	 * 印章销毁接收
	 * 
	 * @param seal_id
	 *            印章id
	 * @param over_log
	 *            印章上缴流转信息
	 * @param save_user_id
	 *            接收用户id
	 * @return
	 */
	@RequestMapping("/recieve")
	public ModelAndView recieve(String seal_id, t_seal_over_log over_log,
			String save_user_id) {

		if (service.recieve(seal_id, over_log, save_user_id)) {
			super.setTipMsg("接收成功!", Tip.Type.success);
			logT.logH("印章接收", t_seal.class, seal_id);
		} else {
			super.setTipMsg("接收失败!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}
